package servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;

import model.AddMasterImpl;
import model.AddUserImpl;
import model.PollUserImpl;
import bean.PollUser;
import java.sql.Date;

public class AddUserServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost (request, response);
	}
	
	public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("GBK");
		System.out.println("here");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String generic = request.getParameter("generic");
		String email = request.getParameter("email");
		String fname = request.getParameter("fname");
		String lname = request.getParameter("lname");
		System.out.println("Username:"+username+" Password:"+password+" generic:"+generic+" email:"+email+" fname:"+fname+" lname:"+ lname);
		PollUser user = new PollUser();
		user.setAccessibility(1);
		user.setCreateDate(new java.sql.Date(System.currentTimeMillis()));
		user.setEmail(email);
		user.setFirstname(fname);
		user.setLastname(lname);
		if(generic=="true"){
			user.setGenericUser(1);
		}else{
			user.setGenericUser(0);
		}
		user.setPassword(password);
		
		AddUserImpl impl = new AddUserImpl(user);
		
		String status;
		if(impl.add()){
			status = "good";
		}else{
			status = "bad";
		}
		try{
			
		}catch(Exception e){
			System.out.println("setQuestionState: Problem's here!");
		}
	}
}
